<template>
  <div class="section clearfix">
    <el-row>
      <el-col :span="4" style="margin-right: 30px">
        <div class="left">
          <div @click="all" class="all">全部</div>
          <el-tree
            :data="data"
            :props="defaultProps"
            @node-click="handleNodeClick"
          ></el-tree>
        </div>
      </el-col>
      <el-col :span="19">
        <div class="empl">
          <el-form
            ref="formInline"
            :inline="true"
            :model="formInline"
            class="demo-form-inline"
            style="text-align: left"
            label-width="90px"
          >
            <el-form-item label="关键词" prop="keyword">
              <el-input
                v-model="formInline.keyword"
                placeholder="用户姓名、身份证号、电话等"
              ></el-input>
            </el-form-item>
            <el-form-item label="在职状态" prop="postStatus">
              <el-select v-model="formInline.postStatus" placeholder="在职状态">
                <el-option
                  v-for="item in newjobState"
                  :key="item.value"
                  :label="item.itemText"
                  :value="item.itemValue"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="员工类型" prop="empClass">
              <el-select v-model="formInline.empClass" placeholder="员工类型">
                <el-option
                  v-for="item in newemployee"
                  :key="item.value"
                  :label="item.itemText"
                  :value="item.itemValue"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="操作端开通" prop="workingEnd">
              <el-select
                v-model="formInline.workingEnd"
                placeholder="操作端开通"
              >
                <el-option
                  v-for="item in workingData"
                  :key="item.value"
                  :label="item.itemText"
                  :value="item.itemValue"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="职级" prop="positionGrade">
              <el-select v-model="formInline.positionGrade" placeholder="职级">
                <el-option
                  v-for="item in newrank"
                  :key="item.id"
                  :label="item.positionName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="账号状态" prop="idStatus">
              <el-select v-model="formInline.idStatus" placeholder="账号状态">
                <el-option
                  v-for="item in newastatus"
                  :key="item.value"
                  :label="item.itemText"
                  :value="item.itemValue"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="渠道类型" prop="trenchType">
              <el-select v-model="formInline.trenchType" placeholder="渠道类型">
                <el-option
                  v-for="item in newTrenchStatus"
                  :key="item.id"
                  :label="item.itemText"
                  :value="item.itemValue"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="渠道人员" prop="keyword">
              <el-input
                v-model="formInline.trenchPersonnel"
                placeholder="渠道人员"
              ></el-input>
            </el-form-item>
            <el-form-item label="是否合伙人" prop="teamPartnerStatus">
              <el-select
                v-model="formInline.teamPartnerStatus"
                placeholder="是否合伙人"
              >
                <el-option
                  v-for="item in newSpreadStatus"
                  :key="item.id"
                  :label="item.itemText"
                  :value="item.itemValue"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="上级合伙人" prop="superiorPartner">
              <el-input
                v-model="formInline.superiorPartner"
                placeholder="上级合伙人"
              ></el-input>
            </el-form-item>
            <el-form-item label="是否推广" prop="partnerStatus">
              <el-select
                v-model="formInline.generalizeStatus"
                placeholder="推广"
              >
                <el-option
                  v-for="item in newPartnerStatus"
                  :key="item.id"
                  :label="item.itemText"
                  :value="item.itemValue"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="推广员" prop="generalizePerson">
              <el-input
                v-model="formInline.generalizePerson"
                placeholder="推广员"
              ></el-input>
            </el-form-item>
            <el-form-item label="注册时间" prop="regTime">
              <el-date-picker
                v-model="formInline.regTime"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width: 240px"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="最近登录" prop="recLogn">
              <el-date-picker
                v-model="formInline.recLogn"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width: 240px"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="渠道录件" prop="recLognQd">
              <el-date-picker
                v-model="formInline.recLognQd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width: 240px"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="App小程序" prop="recLognApp">
              <el-date-picker
                v-model="formInline.recLognApp"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width: 240px"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="区域分类" prop="agentType">
              <el-select v-model="formInline.agentType" placeholder="请选择">
                <el-option
                  v-for="item in classifications"
                  :key="item.itemValue"
                  :label="item.itemText"
                  :value="item.itemValue"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="btn">
              <el-button type="danger" @click="clearForm" v-no-more-click
                >清空</el-button
              >
              <el-button type="primary" @click="onSubmit" v-no-more-click
                >查询</el-button
              >
            </el-form-item>
          </el-form>
          <el-form>
            <el-form-item style="text-align: left">
              <el-button
                @click="exportDept"
                v-if="employeeExportEmpBtn"
                style="width: 80px; height: 32px; line-height: 0"
                v-no-more-click
                >导出</el-button
              >
              <el-button
                @click="add"
                v-if="employeeSaveBtn"
                style="height: 32px; line-height: 0"
                v-no-more-click
                >+添加员工</el-button
              >
              <el-button
                @click="addBatch"
                v-if="employeeOpenBatchBtn"
                style="height: 32px; line-height: 0"
                v-no-more-click
                >+批量开通端口</el-button
              >
            </el-form-item>
          </el-form>
          <el-table
            :data="tableData"
            border
            stripe
            style="width: 100%; position: relative"
            @selection-change="changeFun"
          >
            <el-table-column
              type="selection"
              width="50"
              ref="multipleTable"
              class-name="checkBox"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="jobNumber"
              label="工号"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="employeeName"
              label="姓名"
              fixed="left"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="cardNumber"
              label="身份证号"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="phoneNumber"
              label="手机号"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="email"
              label="邮箱"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="firmName"
              label="所属公司"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="agentTypeName"
              label="一级归类"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="deptName"
              label="所属部门"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="postStatus"
              label="在职状态"
              align="center"
              :formatter="postStatusFormat"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="positionName"
              label="职级"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="empClass"
              label="员工类型"
              align="center"
              :formatter="empClassFormat"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="teamPartnerStatus"
              label="是否团队合伙人"
              align="center"
              :formatter="teamPartnerStatus"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="superiorPartner"
              label="上级合伙人"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="bigDataStatus"
              label="大数据系统"
              align="center"
              width="100"
              :formatter="bigDataStatusFormat"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="miniApp"
              label="经纪人小程序"
              align="center"
              width="110"
              :formatter="miniAppFormat"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="recordMiniApp"
              label="录单小程序"
              align="center"
              width="110"
              :formatter="recordMiniAppFormat"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="trenchType"
              label="渠道类型"
              align="center"
              :formatter="trenchType"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="trenchPersonnel"
              label="渠道人员"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="createTime"
              label="注册时间"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="recentlyLoginTime"
              label="最近登录"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="appLoginTime"
              label="小程序及APP"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="channelLoginTime"
              label="渠道录件系统"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="generalizeStatus"
              label="是否推广"
              align="center"
              :formatter="partnerStatusIs"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="generalizePerson"
              label="推广员"
              align="center"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="idStatus"
              label="账号状态"
              align="center"
              :formatter="idStatusFormat"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              label="操作"
              width="120"
              align="center"
              fixed="right"
              v-if="
                employeeUpdateBtn ||
                employeeBiddenBtn ||
                employeeEnableBtn ||
                employeeDeleteBtn
              "
            >
              <template slot-scope="scope">
                <el-button
                  @click="updateInfor(scope.row)"
                  type="text"
                  size="small"
                  v-if="employeeUpdateBtn"
                  style="color: #ffa42f"
                  v-no-more-click
                  >修改</el-button
                >
                <!-- <el-button
                  @click="disableInfor(scope.row)"
                  type="text"
                  size="small"
                  >禁用</el-button
                >-->
                <el-popconfirm
                  title="确定禁用此数据吗？"
                  @onConfirm="disableInfor(scope.$index, scope.row)"
                  v-if="scope.row.idStatus == 1 && employeeBiddenBtn"
                >
                  <el-button
                    slot="reference"
                    type="text"
                    size="small"
                    v-if="scope.row.idStatus == 1 && employeeBiddenBtn"
                    v-no-more-click
                    >禁用</el-button
                  >
                </el-popconfirm>
                <el-popconfirm
                  title="确定启用此数据吗？"
                  @onConfirm="enableInfor(scope.$index, scope.row)"
                  v-if="scope.row.idStatus == 0 && employeeEnableBtn"
                >
                  <el-button
                    slot="reference"
                    type="text"
                    size="small"
                    v-if="scope.row.idStatus == 0 && employeeEnableBtn"
                    v-no-more-click
                    >启用</el-button
                  >
                </el-popconfirm>
                <el-popconfirm
                  title="确定删除此数据吗？"
                  @onConfirm="deleteData(scope.$index, scope.row)"
                  v-if="employeeDeleteBtn"
                >
                  <el-button
                    slot="reference"
                    type="text"
                    size="small"
                    v-if="employeeDeleteBtn"
                    style="color: #fb575e"
                    v-no-more-click
                    >删除</el-button
                  >
                </el-popconfirm>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!--分页控件-->
        <div class="pagination">
          <span class="title">小计：共{{ this.formInline.total }}条数据</span>
          <el-pagination
            background
            layout="total,prev, pager, next"
            :total="formInline.total"
            :page-size="formInline.pagesize"
            :current-page.sync="currentPage"
            @current-change="handleCurrentChange"
            @size-change="handleSizeChange"
          ></el-pagination>
        </div>
      </el-col>
    </el-row>
    <!--新增修改-->
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="800px"
      top="30px"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <Employ
        :dialogVisible="dialogVisible"
        :newjobState="jobData"
        :newemployee="newempData"
        :newrank="rankData"
        :newastatus="accountData"
        :newadd="isNew"
        :tableInform="tableInform"
        :deptData="deptData"
        :trenchStatus="trenchStatus"
        :partnerStatus="partnerStatus"
        :spreadStatus="spreadStatus"
        v-if="dialogVisible"
        @handleNodeClick="getTbEmployee"
        v-on:dialogVisible="closeDialog($event)"
      ></Employ>
    </el-dialog>
    <!--批量-->
    <el-dialog title="批量开通/关闭端口" :visible.sync="dialog" width="800px">
      <el-form :model="formBatch" label-width="100px">
        <el-form-item label="大数据系统">
          <el-radio-group v-model="formBatch.bigDataStatus" @change="bigBatch">
            <el-radio
              :label="item.itemValue"
              :key="item.itemValue"
              v-for="item in batchData"
              >{{ item.itemText }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="录单小程序">
          <el-radio-group v-model="formBatch.recordStatus" @change="appBatch">
            <el-radio
              :label="item.itemValue"
              :key="item.itemValue"
              v-for="item in batchData"
              >{{ item.itemText }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog = false" v-no-more-click>取 消</el-button>
        <el-button type="primary" @click="batch" v-no-more-click
          >提 交</el-button
        >
      </span>
    </el-dialog>
    <!--    导出-->
    <el-dialog title="导出" :visible.sync="exportdialog" width="20%">
      <span>是否确认导出所有数据?</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="exportdialog = false" v-no-more-click
          >取 消</el-button
        >
        <el-button type="primary" @click="exportDept" v-no-more-click
          >提 交</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import Employ from "../../components/system/Employ";
// import Batch from "../components/Batch";
import {
  orginlistTree,
  getJobStates,
  getEmployee,
  getOpening,
  getRank,
  getAstatus,
  batchCompanyEmploy,
  getTbfindOne,
  getGradeList,
  enableCompanyEmploy,
  areaClassification,
  // exportCompany
  // disableCompanyEmploy
} from "../../../src/assets/js/api";
import { expotOut, checkPermiss, GMTToStr } from "../../assets/js/utlis";

export default {
  name: "Employees",
  components: { Employ },
  data() {
    return {
      multipleSelection: [],
      // show: false,
      isNew: true,
      tableInform: {},
      title: "",
      dialogVisible: false,
      exportdialog: false,
      dialog: false,
      data: [],
      defaultProps: {
        children: "children",
        label: "label",
      },
      formBatch: {
        recordStatus: "2",
        bigDataStatus: "2",
      },
      ids: [],
      postStatus: [{ itemValue: null, itemText: "不限" }],
      newjobState: [],
      empClass: [{ itemValue: null, itemText: "不限" }],
      newemployee: [],
      workingEnd: [{ itemValue: null, itemText: "不限" }],
      newopening: [],
      positionGrade: [{ id: null, positionName: "不限" }],
      newrank: [],
      idStatus: [{ itemValue: null, itemText: "不限" }],
      trenchStatus: [],
      newTrenchStatus: [{ itemValue: null, itemText: "不限" }],
      spreadStatus: [],
      newSpreadStatus: [],
      partnerStatus: [],
      newPartnerStatus: [],
      newastatus: [],
      batchData: [],
      jobData: [],
      newempData: [],
      rankData: [],
      accountData: [],
      idData: [],
      // 查询
      formInline: {
        agentType: null, //区域归类
        keyword: null,
        postStatus: null,
        empClass: null,
        workingEnd: null,
        positionGrade: null,
        idStatus: null,
        firmId: null,
        deptId: null,
        trenchType: null,
        generalizeStatus: null,
        beginEnrollTime: null,
        bendRecentlyLoginTime: null,
        teamPartnerStatus: null, //是否合伙人!
        recLogn: null,
        regTime: null,
        recLognQd: null,
        recLognApp: null,
        pagesize: 10,
        pageNo: 1,
        total: 10,
      },

      classifications: [], // 区域归类筛选数据!
      fileParmas: {
        agentType: null, //区域归类
        keyword: null,
        postStatus: null,
        empClass: null,
        workingEnd: null,
        positionGrade: null,
        idStatus: null,
        firmId: null,
        deptId: null,
      },
      tableData: [],
      gradeData: [],
      deptData: [],
      workingData: [],
      currentPage: 1,
    };
  },
  created() {
    this.golbalPermissions = localStorage.getItem("permissions").split(",");
    this.firstData();
    this.gitlist();
    this.getJobStates();
    this.getEmployee();
    this.getOpening();
    this.getRank();
    this.getAstatus();
    this.getid();
    this.workingType();
    this.getTrenchType();
    this.getSpread();
    this.getPartner();
    this.getClassification();
  },
  //监听删除数据如果是这一页的最后一条数据，返回上一页
  watch: {
    "formInline.total": {
      handler() {
        if (
          this.formInline.total ==
            (this.formInline.pageNo - 1) * this.formInline.pagesize &&
          this.formInline.total != 0
        ) {
          this.formInline.pageNo -= 1;
          this.getlist(this.formInline); //获取列表数据
        }
      },
      deep: true,
      immediate: true,
    },
  },
  computed: {
    // 添加
    employeeSaveBtn: function () {
      return checkPermiss("sys:employee:save", this.golbalPermissions);
    },
    // 编辑
    employeeUpdateBtn: function () {
      return checkPermiss("sys:employee:update", this.golbalPermissions);
    },
    // 删除
    employeeDeleteBtn: function () {
      return checkPermiss("sys:employee:delete", this.golbalPermissions);
    },
    // 启用
    employeeEnableBtn: function () {
      return checkPermiss("sys:employee:enable", this.golbalPermissions);
    },
    // 导出
    employeeExportEmpBtn: function () {
      return checkPermiss("sys:employee:exportEmp", this.golbalPermissions);
    },
    // 批量
    employeeOpenBatchBtn: function () {
      return checkPermiss("sys:employee:openBatch", this.golbalPermissions);
    },
    // 禁用
    employeeBiddenBtn: function () {
      return checkPermiss("sys:employee:bidden", this.golbalPermissions);
    },
  },
  methods: {
    // 获取区域归类!
    getClassification() {
      areaClassification().then((res) => {
        this.classifications = res.data;
      });
    },
    //获取各字典方法
    // 在职
    getJobStates() {
      getJobStates("post_status").then((res) => {
        let arr = res.data;
        let arr2 = arr.map(function (arr) {
          arr.id = parseInt(arr.itemValue);
          return arr;
        });
        this.jobData = arr2;
        this.newjobState = this.postStatus.concat(res.data);
        this.formInline.postStatus = this.newjobState[0].itemText;
      });
    },
    // 员工类型
    getEmployee() {
      getEmployee("emp_type").then((res) => {
        let arr = res.data;
        let arr2 = arr.map(function (arr) {
          arr.id = parseInt(arr.itemValue);
          return arr;
        });
        this.newempData = arr2;
        this.newemployee = this.empClass.concat(res.data);
        this.formInline.empClass = this.newemployee[0].itemText;
      });
    },
    // 操作端
    getOpening() {
      getOpening("open_status").then((res) => {
        this.batchData = res.data;
        this.newopening = this.workingEnd.concat(res.data);
        this.formInline.workingEnd = this.newopening[0].itemText;
      });
    },
    // 职级
    getRank() {
      getRank("rank").then((res) => {
        this.rankData = res.data;
        this.newrank = this.positionGrade.concat(res.data);
        this.formInline.positionGrade = this.newrank[0].positionName;
      });
    },
    // 搜索框操作端开通数据
    workingType() {
      getOpening("working_type").then((res) => {
        this.workingData = this.workingEnd.concat(res.data);
        this.formInline.workingEnd = this.workingData[0].itemText;
      });
    },
    // 账号状态
    getAstatus() {
      getAstatus("account_state").then((res) => {
        let arr = res.data;
        let arr2 = arr.map(function (arr) {
          arr.id = parseInt(arr.itemValue);
          return arr;
        });
        this.accountData = arr2;
        this.newastatus = this.idStatus.concat(res.data);
        this.formInline.idStatus = this.newastatus[0].itemText;
      });
    },
    // 操作状态
    getid() {
      getAstatus("working_open").then((res) => {
        this.idData = res.data;
      });
    },
    //渠道类型
    getTrenchType() {
      getAstatus("trench_status").then((res) => {
        let arr = res.data;
        let arr2 = arr.map(function (arr) {
          arr.id = parseInt(arr.itemValue);
          return arr;
        });
        this.trenchStatus = arr2;
        this.newTrenchStatus = this.idStatus.concat(res.data);
        this.formInline.trenchType = this.newTrenchStatus[0].itemText;
      });
    },
    //是否合伙人
    getSpread() {
      getAstatus("partner_status").then((res) => {
        let arr = res.data;
        let arr2 = arr.map(function (arr) {
          arr.id = parseInt(arr.itemValue);
          return arr;
        });
        this.spreadStatus = arr2;
        this.newSpreadStatus = this.idStatus.concat(res.data);
        this.formInline.teamPartnerStatus = this.newSpreadStatus[0].itemText;
      });
    },
    //是否推广
    getPartner() {
      getAstatus("partner_status").then((res) => {
        let arr = res.data;
        let arr2 = arr.map(function (arr) {
          arr.id = parseInt(arr.itemValue);
          return arr;
        });
        this.partnerStatus = arr2;
        this.newPartnerStatus = this.idStatus.concat(res.data);
        this.formInline.generalizeStatus = this.newPartnerStatus[0].itemText;
      });
    },
    //是否团队合伙人
    teamPartnerStatus(row) {
      return this.selectDictLabel(this.spreadStatus, row.teamPartnerStatus);
    },
    //是否推广翻译
    partnerStatusIs(row) {
      return this.selectDictLabel(this.partnerStatus, row.generalizeStatus);
    },
    //渠道类型
    trenchType(row) {
      return this.selectDictLabel(this.newTrenchStatus, row.trenchType);
    },
    //是否推广员
    generalizeStatus(row) {
      return this.selectDictLabel(this.newPartnerStatus, row.generalizeStatus);
    },
    // 在职状态字典翻译
    postStatusFormat(row) {
      return this.selectDictLabel(this.jobData, row.postStatus);
    },
    // 职级翻译
    positionGradeFormat(row) {
      return this.selectDictLabel(this.newempData, row.positionName);
    },
    // 员工类型
    empClassFormat(row) {
      return this.selectDictLabel(this.newempData, row.empClass);
    },
    // 大数据
    bigDataStatusFormat(row) {
      return this.selectDictLabel(this.idData, row.bigDataStatus);
    },
    // 经纪人
    miniAppFormat(row) {
      return this.selectDictLabel(this.idData, row.miniApp);
    },
    // 录单
    recordMiniAppFormat(row) {
      return this.selectDictLabel(this.idData, row.recordMiniApp);
    },
    // 账号状态
    idStatusFormat(row) {
      return this.selectDictLabel(this.accountData, row.idStatus);
    },
    /**
     * 获取数据
     */
    // 公司部门树
    gitlist() {
      orginlistTree().then((res) => {
        this.data = res.data;
      });
    },
    // 初次获取数据
    firstData() {
      const token = localStorage.getItem("token");
      let pagesize = this.formInline.pagesize;
      let pageNo = this.formInline.pageNo;
      let query = { pagesize, pageNo };
      this.axios
        .get("/sys/tbEmployee/page", {
          //参数列表
          params: query,
          //请求头配置
          headers: { token: token },
        })
        .then((res) => {
          this.tableData = res.data.data.records;
          //this.formInline.pagesize = res.data.data.size;
          this.formInline.pageNo = res.data.data.current;
          this.formInline.total = res.data.data.total;
        });
    },
    //获取员工数据
    getTbEmployee() {
      this.conversion();
      const token = localStorage.getItem("token");
      let querryData = JSON.parse(JSON.stringify(this.formInline));
      //注册日期
      if (querryData.regTime && querryData.regTime[0]) {
        querryData.beginEnrollTime = GMTToStr(querryData.regTime[0]);
        querryData.endEnrollTime = GMTToStr(querryData.regTime[1]);
      }
      //登录日期
      if (querryData.recLogn && querryData.recLogn[0]) {
        querryData.beginRecentlyLoginTime = GMTToStr(querryData.recLogn[0]);
        querryData.endRecentlyLoginTime = GMTToStr(querryData.recLogn[1]);
      }
      // 渠道系统登录时间
      if (querryData.recLognQd && querryData.recLognQd[0]) {
        querryData.beginChannelLoginTime = GMTToStr(querryData.recLognQd[0]);
        querryData.endChannelLoginTime = GMTToStr(querryData.recLognQd[1]);
      }
      // app小程序登录时间
      if (querryData.recLognApp && querryData.recLognApp[0]) {
        querryData.beginAppLoginTime = GMTToStr(querryData.recLognApp[0]);
        querryData.endAppLoginTime = GMTToStr(querryData.recLognApp[1]);
      }

      delete querryData.regTime;
      delete querryData.recLogn;
      delete querryData.recLognQd;
      delete querryData.recLognApp;
      this.axios
        .get("/sys/tbEmployee/page", {
          //参数列表
          params: querryData,
          //请求头配置
          headers: { token: token },
        })
        .then((res) => {
          this.tableData = res.data.data.records;
          this.formInline.pagesize = res.data.data.size;
          this.formInline.pageNo = res.data.data.current;
          this.formInline.total = res.data.data.total;
        });
    },
    /**
     * 搜索功能
     */
    // 点击公司部门树进行搜索
    handleNodeClick(data) {
      if (data.id) {
        this.formInline.firmId = data.id;
        if (data.otherId !== null) {
          this.formInline.firmId = data.otherId;
          this.formInline.deptId = data.id;
        } else {
          this.formInline.deptId = "";
        }
        const token = localStorage.getItem("token");
        let firmId = this.formInline.firmId;
        let deptId = this.formInline.deptId;
        let pagesize = this.formInline.pagesize;
        let pageNo = 1;
        let query = { firmId, deptId, pagesize, pageNo };
        this.axios
          .get("/sys/tbEmployee/page", {
            //参数列表
            params: query,
            //请求头配置
            headers: { token: token },
          })
          .then((res) => {
            this.tableData = res.data.data.records;
            this.formInline.pagesize = res.data.data.size;
            this.formInline.pageNo = res.data.data.current;
            this.formInline.total = res.data.data.total;
          });
      }
    },
    // 搜索框添加默认值
    conversion() {
      
      let obj = this.formInline;
      console.log(obj);
      if (obj.postStatus == "不限") {
        obj.postStatus = null;
      }
      if (obj.empClass == "不限") {
        obj.empClass = null;
      }
      if (obj.workingEnd == "不限") {
        obj.workingEnd = null;
      }
      if (obj.positionGrade == "不限") {
        obj.positionGrade = null;
      }
      if (obj.idStatus == "不限") {
        obj.idStatus = null;
      }
      if (obj.trenchType == "不限") {
        obj.trenchType = null;
      }
      if (obj.generalizeStatus == "不限") {
        obj.generalizeStatus = null;
      }
      if (obj.teamPartnerStatus == "不限") {
        obj.teamPartnerStatus = null;
      }
      
     if (obj.agentType == "不限") {
        obj.agentType = null;
      }
    },
    // 搜索功能
    onSubmit() {
      // this.conversion();
      this.formInline.pageNo = 1;
      if (this.formInline.beginEnrollTime) {
        this.formInline.beginEnrollTime = GMTToStr(
          this.formInline.beginEnrollTime
        );
      }
      if (this.formInline.bendRecentlyLoginTime) {
        this.formInline.bendRecentlyLoginTime = GMTToStr(
          this.formInline.bendRecentlyLoginTime
        );
      }
      this.getTbEmployee();
      this.currentPage = 1;
    },
    //清空按钮
    clearForm() {
      this.formInline.agentType = "";
      this.formInline.keyword = "";
      this.formInline.postStatus = "不限";
      this.formInline.empClass = "不限";
      this.formInline.workingEnd = "不限";
      this.formInline.positionGrade = "不限";
      this.formInline.idStatus = "不限";
      this.formInline.trenchType = "不限";
      this.formInline.generalizeStatus = "不限";
      this.formInline.teamPartnerStatus = "不限";
      this.formInline.superiorPartner = null;
      this.formInline.trenchPersonnel = null;
      this.formInline.generalizePerson = null;
      this.formInline.regTime = null;
      this.formInline.recLogn = null;
      this.formInline.recLognQd = null;
      this.formInline.recLognApp = null;
      this.formInline.pageNo = 1;
      //this.$refs.formInline.resetFields();
    },
    /**
     * 操作
     */
    // 打开新增弹框
    add() {
      this.dialogVisible = true;
      this.isNew = true;
      this.currentPage = 1;
      this.title = "新增";
    },
    //修改按钮
    updateInfor(row) {
      getTbfindOne(row.id).then((res) => {
        this.tableInform = res.data;
        // 获取职级
        getGradeList().then((res) => {
          this.gradeData = res.data.data;
        });
        // 获取部门
        this.dialogVisible = true;
        this.isNew = false;
        this.title = "修改";
      });
    },
    //关闭弹窗
    closeDialog(msg) {
      this.dialogVisible = msg;
    },
    // 左侧全部按钮点击事件
    all() {
      this.formInline.pageNo = 1;
      this.currentPage = 1;
      this.formInline.deptId = null;
      this.formInline.firmId = null;
      this.clearForm();
      this.firstData();
    },
    // 获取选中表格数据
    changeFun(val) {
      this.ids = val.map((item) => item.id);
    },
    // 打开批量添加
    addBatch() {
      this.dialog = true;
    },
    // 批量提交按钮
    batch() {
      let data = {
        ids: this.ids,
        bigDataStatus: this.formBatch.bigDataStatus,
        recordStatus: this.formBatch.recordStatus,
      };
      if (this.ids.length > 0) {
        batchCompanyEmploy(data).then((res) => {
          if (res.code === 200) {
            this.dialog = false;
            this.$message({
              message: "批量开通/关闭端口成功",
              type: "success",
            });
            this.getTbEmployee();
          } else {
            this.dialog = false;
            this.$message({
              message: "批量开通/关闭端口失败",
              type: "error",
            });
            this.getTbEmployee();
          }
        });
      } else {
        this.dialog = false;
        this.$message({
          message: "请选择需要批量开通/关闭端口的人员",
          type: "error",
        });
      }
    },
    // 大数据系统选择按钮
    bigBatch(item) {
      this.formBatch.bigDataStatus = item;
    },
    // 录单小程序选择按钮
    appBatch(item) {
      this.formBatch.recordStatus = item;
    },
    //删除数据
    deleteData(index, obj) {
      this.codeId = obj.id;
      this.axios({
        method: "delete",
        url: "/sys/tbEmployee/delete/" + this.codeId,
      }).then((res) => {
        if (res.data.code === 200) {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.getTbEmployee();
        } else {
          this.$message({
            message: "删除失败",
            type: "error",
          });
          this.getTbEmployee();
        }
      });
    },
    // 禁用
    disableInfor(index, obj) {
      this.codeId = obj.id;
      this.axios({
        method: "put",
        url: "/sys/tbEmployee/bidden/" + this.codeId,
      }).then((res) => {
        if (res.data.code === 200) {
          this.$message({
            message: res.data.message,
            type: "success",
          });
          this.getTbEmployee();
        } else {
          this.$message({
            message: res.data.message,
            type: "error",
          });
          this.getTbEmployee();
        }
      });
    },
    // 启用
    enableInfor(index, obj) {
      enableCompanyEmploy(obj.id).then((res) => {
        if (res.code === 200) {
          this.$message({
            message: res.message,
            type: "success",
          });
          this.getTbEmployee();
        } else {
          this.$message({
            message: res.message,
            type: "error",
          });
          this.getTbEmployee();
        }
      });
    },
    //分页
    handleCurrentChange(cpage) {
      this.formInline.pageNo = cpage;
      this.getTbEmployee();
    },
    handleSizeChange(psize) {
      this.formInline.pageNo = psize;
      this.getTbEmployee();
    },
    //  导出
    exportDept() {
      this.conversion();
      this.fileParmas.agentType = this.formInline.agentType;
      this.fileParmas.keyWord = this.formInline.keyWord;
      this.fileParmas.postStatus = this.formInline.postStatus;
      this.fileParmas.empClass = this.formInline.empClass;
      this.fileParmas.workingEnd = this.formInline.workingEnd;
      this.fileParmas.positionGrade = this.formInline.positionGrade;
      this.fileParmas.idStatus = this.formInline.idStatus;
      this.fileParmas.firmId = this.formInline.firmId;
      this.fileParmas.deptId = this.formInline.deptId;

      expotOut(
        "get",
        "/sys/tbEmployee/exportEmp",
        this.fileParmas, // 导出请求参数
        "员工管理" // 导出文件名字
      );
    },
  },
};
</script>

<style scoped type="less">
.left
{
    overflow-x: hidden;  height: 400px;  box-shadow: 0 0 10px rgb(193, 193, 193);
}
::v-deep .el-dialog__footer
{
    text-align: center;
}
::v-deep .el-table td
{
    padding: 10px 0;
}
::v-deep .el-table th
{
    padding: 10px 0;
}
.all
{
    line-height: 30px;  height: 30px;
}
.all:hover
{
    cursor: pointer;  background-color: rgb(243, 243, 243);
}
::v-deep .el-form--inline .el-form-item__content
{
    line-height: 42px;  width: 210px;
}
.demo-form-inline ::v-deep .el-input__inner
{
    height: 32px;
}
.demo-form-inline ::v-deep .el-input__icon
{
    line-height: 32px;
}
::v-deep .btn .el-button
{
    line-height: 0;  width: 80px;  height: 32px;
}
::v-deep .el-table th > .cell
{
    font-size: 14px;  font-weight: bold;  color: #333;
}
::v-deep .el-table--striped .el-table__body tr.el-table__row--striped td
{
    background: rgba(59, 157, 248, .1);
}
::v-deep .el-col-19
{
    position: relative;
}
::v-deep .el-pagination
{
    position: absolute;  right: 0;  margin-top: 20px;
}
::v-deep .el-pagination__total
{
    visibility: hidden;
}
.title
{
    font-family: Microsoft YaHei;  font-size: 12px;  font-weight: 400;  line-height: 21px;  position: absolute;  left: 0;  margin-top: 15px;  color: rgba(51, 51, 51, 1);
}
.empl .el-form-item
{
    line-height: 32px;  height: 32px;  margin-bottom: 15px;
}
.empl ::v-deep .el-form-item__label,
.empl ::v-deep .el-form-item__content
{
    line-height: 32px;  height: 32px;
}
.empl ::v-deep .el-input__icon,
.empl ::v-deep .el-range-separator
{
    line-height: 24px;
}
::v-deep .el-range-editor.el-input__inner
{
    width: 210px !important;  padding: 3px 0 3px 5px;
}







</style>
